package com.example.exam.controller;


import com.example.exam.bean.Student;
import com.example.exam.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController

public class StudentController {

    @Autowired
    @Qualifier("studentService")
    StudentService StudentService;

    @GetMapping("/Students")

    public List<Student> getAllStudents(){
        return  StudentService.list();
    }
    @GetMapping("/Student/{id}")

    public Student getStudentById(@PathVariable("id")  Integer id){
        return StudentService.getById(id);
    }
    @PostMapping("/Student")

    public String addStudent(@RequestBody Student Student){
        if (StudentService.save(Student)){
            return "添加学生成功！";
        }else {
            return "添加学生失败";
        }
    }
    @PutMapping("/Student")

    public String updateStudent(@RequestBody Student Student){
        if (StudentService.updateById(Student)){
            return "修改学生成功！";
        }else {
            return "修改学生失败";
        }
    }

    @DeleteMapping("/Student")

    public String deleteStudent(Integer id){
        if (StudentService.removeById(id)){
            return "删除学生成功！";
        }else {
            return "删除学生失败";
        }
    }

}
